<?php
namespace app\controller;

use app\BaseController;
use app\Request;
use app\validate\Handle;
use Lorine\OssUtils\OssService;
use think\Exception;
use think\exception\ValidateException;

class Index extends BaseController
{
// 举报页面
function handleShow(){
    return view('index/handleShow');
}
//举报数据
function handleData(Request $request){
    $postData=$request->all();
    try {
        validate(Handle::class)->check($postData);
    } catch (ValidateException $e) {
        // 验证失败 输出错误信息
        dd($e->getError());
    }
    $file=$request->file('file');
    $config = [
        'ak' => 'X-yoT01fun3kgDBUmwxoA7zgFDJ6RH-A9jZ5tbWf',//SecretId /Access_Key
        'sk' => 'NgVB-zQXwc3B_QmNsZZ9fF7SbrN63L_k4zWsDTqB',//SecretKe /Secret_Key
        'bucket' => 'zbb0109',//桶名
        'region' => ''//地区 七牛云为''，腾讯云在控制台对象存储界面获取，如上海（ap-shanghai）
    ];
    try {
        //云存储类型 腾讯云：Tencent  七牛云：Qiniu
        $obj = (new OssService())->getOssService('Qiniu');
        //$tmpName绝对路径
        $tmpName=$file->getPathname();
        //$fileName自定义云储存的文件名称
        $fileName=time().'.'.$file->getOriginalExtension();
        $res = $obj->uploadFile($config,$tmpName,$fileName);
        $res=\Qiniu\json_decode($res);
    }catch (Exception $exception){
        dd($exception->getMessage());
    }
    $postData['file']=$res->data;
    $checkData=\app\model\Index::handleData($postData);
    if($checkData){
        return success($checkData,200,'提交成功');
    }
}
}
